#include<stdio.h>
#include<math.h>
int main ()
{
	int t;
	scanf("%d",&t);
	double num;int location;
	while(t--)
	{
		scanf("%lf %d",&num,&location);
		num=num*pow(10,location);
		printf("%d\n",((int)num)%10);
	}
	return 0;
}
